﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DmPlayer
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        DmCanvas dmCanvas;
        public static MainWindow logWindow;
        Random random = new Random();
        DmWsClient client;
        public MainWindow()
        {
            InitializeComponent();
            dmCanvas = new DmCanvas();
            dmCanvas.Show();
            logWindow = this;

            client = new DmWsClient("localhost:8888", "test");
            client.onDmReceived += (dm) => {
                dmCanvas.launchDm(dm);
            };
            client.connect();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            new Thread(() => {
                string[] text = new string[5] { "测试弹幕", "测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕", "测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕测试弹幕", "测试弹幕测试弹幕测试弹幕", "测试弹幕测试弹幕测试弹幕测试弹幕" };
                int[] colors = new int[9] { 0xff6600, 0x00ffff, 0xffffff, 0x0000ff, 0xffff00, 0xff0000, 0x800080, 0xadff2f, 0xffc0cb };
                for (int i = 0; i < 300; i++)
                {
                    dmCanvas.launchDm(new Dm(text[random.Next(0, 5)], "1", "1", "1", "微软雅黑", colors[random.Next(0, 9)], 24, ""));
                    Thread.Sleep(30);
                }
            }).Start();

        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
    }
}
